﻿using UnityEngine;
using System.Collections;
using UICore;
using UnityEngine.UI;
using System.Collections.Generic;

public class PlayUI : BaseUI
{

    
    //蓝条
    private Slider slider;
    //红条
    private Slider slider1;
    //敌人红条
    private Slider slider2;
    private Button btn_Exit; 


    protected override void InitUiOnAwake()
    {
        base.InitUiOnAwake();
        btn_Exit = GameTool.GetTheChildComponent<Button>(this.gameObject,"Btn_Exit");
        btn_Exit.onClick.AddListener(ShowExitPanel);

        slider = GameTool.GetTheChildComponent<Slider>(this.gameObject, "Slider_Progress");
        slider1 = GameTool.GetTheChildComponent<Slider>(this.gameObject, "Slider_Progress1");
        slider2 = GameTool.GetTheChildComponent<Slider>(this.gameObject, "Slider_Progress2");
    }
    protected override void InitDataOnAwake()
    {
        base.InitDataOnAwake();
        this.uiId = E_UiId.PlayUI;
        this.uiType.showMode = E_ShowUIMode.HideAll; 
       
    }
   public static void PassLevel()
    {
        //获取当前开启的最高关卡
        int maxLevel = LevelManager.Instance.GetCurrentMaxLevel();
        //当前进入的关卡
        int currentLevel = LevelManager.Instance.GetCurrentEnterLevel();
        if (currentLevel== maxLevel)
        {
            LevelManager.Instance.SetCurrentMaxLevel(++maxLevel);
        }

        ShowPassPanel();
    }
    public static void NoPassLevel()
    {
        //ShowLevelPanel();
        ShowNoPassPanel();
    }
    public static void ShowLevelPanel()
    {
        LoadSceneManager.Instance.LoadSceneAsync("MainScene", delegate
        {
            UIManager.Instance.ShowUI(E_UiId.InforUI, false);
            UIManager.Instance.ShowUI(E_UiId.LevelUI, false);
        });
    }
    private  void ShowExitPanel()
    {
        UIManager.Instance.ShowUI(E_UiId.ExitUI);
    }
    public static void ShowPassPanel()
    {
        UIManager.Instance.ShowUI(E_UiId.PassUI);

    }
    public static void ShowNoPassPanel()
    {
        UIManager.Instance.ShowUI(E_UiId.NoPassUI);

    }

   //获取蓝条的值
    public float GetSliderValue()
    {
        return slider.value;
    }
    //获取红条的值
    public float GetSlider1Value()
    {
        return slider1.value;
    }
    //获取敌人红条的值
    public float GetSlider2Value()
    {
        return slider2.value;
    }
    //设值为1
    public void SetAllSliderValue()
    {
        slider.value=1.0f;
        slider1.value = 1.0f;
        slider2.value = 1.0f;
    }
    //设红条的值为0
    public void SetSlider1Value()
    {
     
        slider1.value = 0;
    }
    //设敌人红条的值为0
    public void SetSlider2Value()
    {

        slider2.value = 0;
    }
    //减少蓝条
    public void ReduceBlue(float a)
    {

        if (slider.value >= a)
        {
            slider.value = slider.value - a;
        }
    }
    //减少红条
    public void ReduceRed(float a)
    {

        if (slider1.value >= a)
        {
            slider1.value = slider1.value- a;
        }
    }
    //减少敌人红条
    public void ReduceFoeRed(float a)
    {

        if (slider2.value >= a)
        {
            slider2.value = slider2.value - a;
        }
    }
   
    void Update()
    {
        //让进度条走动起来
       slider.value = slider.value + 0.002f;



    }

}
